<template>
  <div>
    <!-- 这是对应列表 -->
    <div
      class="newlistinfo"
      v-for="item in datalist"
      :key="item.id"
      @click="comment(item.id)"
    >
      <div class="left">
        <div class="images">
          <!-- 图片懒加载在这 -->
          <img src="../../assets/images/8.jpg" alt="" />
        </div>
        <div class="title">
          <h1>{{ item.username }}</h1>
          <p>{{ item.create_time | dataFormat }}</p>
        </div>
      </div>
      <div class="right">{{ item.id }}</div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Toast } from 'vant'

Vue.use(Toast)
export default {
  data() {
    return {
      datalist: [],
      // 请求的参数
      queryinfo: {
        query: '',
        pagenum: 1,
        pagesize: 100
      }
    }
  },
  created() {
    this.getlist()
  },
  methods: {
    async getlist() {
      const { data: res } = await this.$http.get('users', {
        params: this.queryinfo
      })
      console.log(res)
      if (res.meta.status !== 200) {
        return Toast('获取新闻列表失败')
      }
      // 获取成功
      this.datalist = res.data.users
    },
    comment(id) {
      // console.log(id)
      this.$router.push(`/login/${id}`)
    }
  }
}
</script>

<style lang="less" scoped>
.newlistinfo {
  height: 64px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  line-height: 64px;
  padding: 10px 10px;
  .left {
    display: flex;
    .images {
      width: 28px;
      height: 42px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      margin-left: 5px;
      h1 {
        font-size: 16px;
        margin: 2px 0 5px 0;
      }
      p {
        height: 20px;
        line-height: 20px;
        margin: 0;
      }
    }
  }
  .right {
    font-size: 13px;
  }
}
</style>
